package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.RoomInfo;
import com.atguigu.lease.model.enums.ReleaseStatus;
import com.atguigu.lease.web.admin.service.RoomInfoService;
import com.atguigu.lease.web.admin.vo.room.RoomDetailVo;
import com.atguigu.lease.web.admin.vo.room.RoomSubmitVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: liuaojun
 * @CreateTime: 2025-02-22
 * @Description:
 * @Version: 1.0
 */
@Tag(name = "房间信息管理")
@RestController
@RequestMapping("/admin/room")
public class RoomController {
    @Autowired
    RoomInfoService roomInfoService;

    @Operation(summary = "根据id修改房间发布状态")
    @PostMapping("updateReleaseStatusById")
    public Result updateReleaseStatusById(Long id, Integer status){
        LambdaUpdateWrapper<RoomInfo> roomInfoLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        roomInfoLambdaUpdateWrapper.eq(RoomInfo::getId, id);
        roomInfoLambdaUpdateWrapper.set(RoomInfo::getIsRelease,status);
        roomInfoService.update(roomInfoLambdaUpdateWrapper);
        return Result.ok();
    }
    @Operation(summary = "根据公寓ID查询房间列表")
    @GetMapping("listBasicByApartmentId")
    public Result<List<RoomInfo>> listBasicByApartmentId(Long apartmentId){
        LambdaQueryWrapper<RoomInfo> roomInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        roomInfoLambdaQueryWrapper.eq(RoomInfo::getApartmentId, apartmentId).eq(RoomInfo::getIsRelease, ReleaseStatus.RELEASED);
        List<RoomInfo> list= roomInfoService.list(roomInfoLambdaQueryWrapper);
        return Result.ok(list);
    }

    @Operation(summary = "根据id获取房间详细信息")
    @GetMapping("getDetailById")
    public Result<RoomDetailVo> getDetailById(@RequestParam Long id){
        RoomDetailVo vo=roomInfoService.getRoomDetailById(id);
        return Result.ok(vo);
    }

    @Operation(summary = "根据id删除房间信息")
    @DeleteMapping("removeById")
    public Result removeById(Long id){
        roomInfoService.removeRoomById(id);
        return Result.ok();
    }

    @Operation(summary = "保存或更新房间信息")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody RoomSubmitVo roomSubmitVo){
        roomInfoService.saveOrUpdateRoom(roomSubmitVo);
        return Result.ok();
    }





}
